home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: "Double to 2 Unsigned Longs"
- Date: 17 Feb 1996 12:30:32 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4g5dt8INNivu@keats.ugrad.cs.ubc.ca>
- References: <4g53ml$haj@portal.gmu.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4g53ml$haj@portal.gmu.edu>,
- Aires C Domingues <adomingu@osf1.gmu.edu> wrote:
- >How to go about storing a double (used to store very large integers) to
- >a user defined 64 bit integer (structure with two unsigned long fields)?
- >
- >The user defined 64 bit integer looks something like this:
- >
- >typedef struct {
- > unsigned long high;
- > unsigned long low;
- >} UINT64;
- >
- >Where "high" is used to save the high order bits for the really big integer,
- >and "low" is used for the low order bits.
- >
- >One idea is to take the double and divide it by 2**32. The we can save the
- >resulting integral part of the division in "high", and the remainder in the
- >"low". This will off-course lead to rounding errors. Any other ideas?
-
- It will not lead to round-off errors on architectures that represent
- floating-point numbers in binary exponential notation. Multiplying and dividing
- by powers of two is equivalent to just adding and subtracting on the floating
- point number's exponent; the mantissa bits stay the same.
-
- Of course, you would be making a lot of machine-specific assumptions in your
- code about the nature of unsigned long numbers, the nature of doubles and their
- relationship. Porting your code to different architectures may require
- tweaking, so I'd abstract and isolate it as much as possible.
- --
-
-